//
//  ST_OptionPopoverViewController.swift
//  btvideo
//
//  Created by mac on 2020/8/5.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

class ST_OptionPopoverViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .clear
        
        view.addSubview(close_btn)
        close_btn.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        view.addSubview(root_view)
        root_view.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize.init(width: 111, height: 152))
            make.top.equalToSuperview().offset(44+5+statusBarHeight)
            make.left.equalToSuperview().offset(10)
        }
        
        
        view.addSubview(top_image_view)
        top_image_view.snp.makeConstraints { (make) in
            make.bottom.equalTo(root_view.snp.top)
            make.left.equalTo(root_view).offset(14)
            make.size.equalTo(CGSize.init(width: 12, height: 8))
        }
        
        root_view.addSubview(searchBtn)
        searchBtn.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalToSuperview().dividedBy(3)
        }
        
        root_view.addSubview(setting_btn)
        setting_btn.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(searchBtn.snp.bottom)
            make.height.equalToSuperview().dividedBy(3)
        }
        
        root_view.addSubview(line0)
        line0.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(searchBtn.snp.bottom)
        }
        
        
        root_view.addSubview(line1)
        line1.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(setting_btn.snp.bottom)
        }
    }

//    MARK: - Properties
    
    fileprivate lazy var line0:UIView = {
        let control = UIView()
        control.backgroundColor = UIColor.init(hex: 0x6E747F)
        return control
    }()
    
    fileprivate lazy var line1:UIView = {
        let control = UIView()
        control.backgroundColor = UIColor.init(hex: 0x6E747F)
        return control
    }()
    
    
    fileprivate lazy var top_image_view:UIImageView = {
        let control = UIImageView.init(image: ST_ImageUtils.imageName("三角形"))
          return control
      }()
    
    fileprivate lazy var close_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.addTarget(self, action: #selector(close_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var root_view:UIView = {
       let control = UIView()
        control.cornerRadius = 10
        control.backgroundColor = UIColor.init(hex: 0x5B6069)
        return control
    }()
    
    fileprivate lazy var searchBtn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setTitleForAllStates(" 搜索用户")
        control.setTitleColor(UIColor.white, for: UIControl.State.normal)
        control.setImageForAllStates(ST_ImageUtils.imageName("首页_icon_option_0")!)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        control.addTarget(self, action: #selector(searchHandle), for: UIControl.Event.touchUpInside)
        return control
    }()

    fileprivate lazy var setting_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setTitleForAllStates(" 偏好设置")
        control.setTitleColor(UIColor.white, for: UIControl.State.normal)
        control.setImageForAllStates(ST_ImageUtils.imageName("首页_icon_option_1")!)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        control.addTarget(self, action: #selector(setting_click_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    

    var search_closure:(()->())?
    var setting_click_closure:(()->())?
}




extension ST_OptionPopoverViewController{
    
    @objc fileprivate func close_handle(){
        
        self.dismiss(animated: false) {
            
        }
    }
    
    @objc fileprivate func searchHandle(){
        
        self.dismiss(animated: false) {
            
            self.search_closure?()
            
        }
    }
    
    @objc fileprivate func setting_click_handle(){
      
        ST_BTUserInfoManager.shared.judge_account_frozen().withUnretained(self).subscribe(onNext: { own,_ in
            
            own.dismiss(animated: false) {
                own.setting_click_closure?()
            }
            
            
        }).disposed(by: rx.disposeBag)
        
    }
    
}
